﻿using DocumentFormat.OpenXml.Presentation;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PPTHelper.BLL.TimingRoot.Controller_
{
    /// <summary>
    /// 时序根控制器：该控制器负责接收信号，并进行信号的派遣。
    /// 
    /// </summary>
    public class TimingRootController
    {
        /// <summary>
        /// 时序树
        /// </summary>
        public Timing Timing { get;}

        // 时序根
        private ParallelTimeNode _timingRoot;

        /// <summary>
        /// 主序列控制器
        /// </summary>
        private MainSequenceController _mainSequenceController;

        /// <summary>
        /// 默认构造方法
        /// </summary>
        /// <param name="timing"></param>
        public TimingRootController(Timing timing)
        {
            if (timing == null)
                throw new ArgumentNullException(nameof(timing));

            Timing = (Timing)timing?.Clone();

            //var childTimeNodeList = parallelTimeNode?.CommonTimeNode?.ChildTimeNodeList;
        }

        /// <summary>
        /// 构建动画控制器
        /// </summary>
        public void BuildAnimateController()
        {
            var parallelTimeNode = Timing?.TimeNodeList?.ParallelTimeNode;

            //
            // 如果时序根下没有并行时间容器，则改Slide可能没有动画。因为tnLst节点下可以有多种类型的容器，目前版本只支持parallel容器。
            //
            if (parallelTimeNode == null)
            {
                throw new Exception("时许树根节点下无Parallel容器。");
            }

            if (parallelTimeNode?.CommonTimeNode?.NodeType == TimeNodeValues.TmingRoot)
            {
                _timingRoot = parallelTimeNode;
            }
            else
            {
                throw new Exception("时序树根节点下无TimingRoot类型容器。");
            }

            
        }

        /// <summary>
        /// 信号派遣
        /// </summary>
        /// <param name="signal"></param>
        public void SignalDispatch(string signal)
        {
            // 幻灯片下一步
            if (signal.Equals("NextStep"))
            {

            }
            else
            // 幻灯片上一步
            if (signal.Equals("LastStep"))
            {

            }
            // 触发器触发
            if(signal.Contains("Trigger"))
            {

            }
        }

        /// <summary>
        /// 构建控制器
        /// </summary>
        /// <param name="childTimeNodeList"></param>
        /// <param name="parent"></param>
        private void BuildController(ChildTimeNodeList childTimeNodeList, TimeNodeContainer parent)
        {

        }
    }
}
